﻿/**
 * @class app.ForumList
 * @namespace app
 * @extends Ext.Panel
 */
app.ForumList = function(configObj) {
    var thisObject = this;

    Ext.regModel('Forum', {
        fields: ['icon', 'text', 'needsIcon']
    });

    var store = new Ext.data.Store({
        model: 'Forum',
		fields: ['icon', 'text', 'needsIcon'],
        data: [
            { icon: 'Restaurant.png', text: 'Restaurants', needsIcon: true },
            { icon: 'Travel.png', text: 'Travel', needsIcon: true },
            { icon: 'Accomodation.png', text: 'Accommodation', needsIcon: true },
            { icon: 'Whats Hot.png', text: 'What\'s hot?', needsIcon: true },
            { icon: 'Pocket info.png', text: 'Pocket Info', needsIcon: true },
            { icon: 'My Account.png', text: 'My Account', needsIcon: true }
        ]
    });
    
    app.ForumList.superclass.constructor.call(this, {
        layout: 'fit',
        dockedItems: [{
            dock: 'top',
            xtype: 'toolbar',
            title: 'Glocal Chinese',
			items: [
			{ui: 'plain', iconCls: 'info', iconMask: true, 
					 handler: function() {
						 app.eventMgr.fireEvent('InfoDetail', null);}
					},
					{xtype: 'spacer'}, 
					{text: 'Login', 
					 handler: function() {app.eventMgr.fireEvent('Login', null);}},
				   ]
        }],
        items: [{
            xtype: 'list',
            itemTpl: '<tpl if="needsIcon"><img width="26" height="26" src="images/{icon}" align="absmiddle" /></tpl>{text}',
            grouped: false,
            store: store,
			ui: 'round',
            scroll : true,
            onItemDisclosure: true,
            listeners: {
                'disclose': function(item, node, index, eventObj) {
                    app.eventMgr.fireEvent(
                        'SelectForum', 
                        item.get('id'), 
                        item.get('text')
                    )
                },
                'destroy': function(thisComponent) {
                    app.eventMgr.un('ForumList', forumList);
                }
            }
        }]
    });

    function forumList() {
        app.page.setActiveItem(0, { type: 'slide', 'direction': 'right' });
    }
	function backToMain() {
        app.page.setActiveItem(0, { type: 'slide', cover: true, 'direction': 'down' });
    }

    app.eventMgr.on('ForumList', forumList);
	app.eventMgr.on('BackToMain', backToMain);
	
};
Ext.extend(app.ForumList, Ext.Panel, {});